import { PlayerPosition, PlayerRank } from '@dx-fun-group/shared-types';

// 位置中文名称映射
export const POSITION_LABELS: Record<PlayerPosition, string> = {
  [PlayerPosition.CARRY]: '优势路',
  [PlayerPosition.MID]: '中路',
  [PlayerPosition.OFFLANE]: '劣势路',
  [PlayerPosition.SUPPORT]: '辅助',
  [PlayerPosition.HARD_SUPPORT]: '纯辅助'
};

// 段位中文名称映射
export const RANK_LABELS: Record<PlayerRank, string> = {
  [PlayerRank.HERALD]: '先锋',
  [PlayerRank.GUARDIAN]: '卫士',
  [PlayerRank.CRUSADER]: '中军',
  [PlayerRank.ARCHON]: '统帅',
  [PlayerRank.LEGEND]: '传奇',
  [PlayerRank.ANCIENT]: '万古流芳',
  [PlayerRank.DIVINE]: '超凡入圣',
  [PlayerRank.IMMORTAL]: '冠绝一世'
};

// 获取位置的中文名称
export const getPositionLabel = (position: PlayerPosition): string => {
  return POSITION_LABELS[position];
};

// 获取段位的中文名称
export const getRankLabel = (rank: PlayerRank): string => {
  return RANK_LABELS[rank];
};

// 获取多个位置的中文名称
export const getPositionsLabel = (positions: PlayerPosition[]): string => {
  return positions.map(getPositionLabel).join('、');
};

// 格式化日期
export const formatDate = (dateString: string): string => {
  const date = new Date(dateString);
  return new Intl.DateTimeFormat('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit'
  }).format(date);
};

// 验证昵称
export const validateNickname = (nickname: string): string | null => {
  if (!nickname.trim()) {
    return '昵称不能为空';
  }
  if (nickname.length > 20) {
    return '昵称长度不能超过20个字符';
  }
  return null;
};

// 验证位置选择
export const validatePositions = (positions: PlayerPosition[]): string | null => {
  if (positions.length === 0) {
    return '请至少选择一个擅长位置';
  }
  return null;
};

// 验证最高天梯分
export const validateHighestMmr = (mmr: number): string | null => {
  if (mmr === null || mmr === undefined || isNaN(mmr)) {
    return '请输入最高天梯分';
  }
  if (mmr < 0) {
    return '天梯分不能小于0';
  }
  if (mmr > 20000) {
    return '天梯分不能大于20000';
  }
  if (!Number.isInteger(mmr)) {
    return '天梯分必须为整数';
  }
  return null;
};

// 闪耀金色选手ID列表
export const SUPER_GOLDEN_PLAYER_IDS = ['115670858', 'example_player_id']

// 检查选手是否为闪耀金色选手
export const isSuperGoldenPlayer = (playerId: string): boolean => {
  return SUPER_GOLDEN_PLAYER_IDS.includes(playerId)
}

// 检查选手是否为普通金色选手
export const isGoldenPlayer = (playerId: string): boolean => {
  return playerId === '188061713'
}
